﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook.Services;
using Facebook;
using System.Collections;
using Facebook.Contracts;

namespace WebApplication1
{
    public partial class Select : System.Web.UI.Page
    {
        IFacebookService facebookservice;

        protected void Page_Load(object sender, EventArgs e)
        {

            facebookservice = this.Session["facebookservice"] as IFacebookService;

            btnSelectConnectionType.Click += new EventHandler(btnSelectConnectionType_Click);
                       
           // dynamic result = facebookservice.Select("me", ConnectionType.home, null);

        }

        void btnSelectConnectionType_Click(object sender, EventArgs e)
        {
            if (facebookservice != null)
            {

                ConnectionType connType = (ConnectionType)Enum.Parse(typeof(ConnectionType), this.listOfConnectionTypes.SelectedItem.Text, false);
                
                
                FacebookEntity result = facebookservice.Select("me", connType,new string[] {"id", "name"}) as FacebookEntity;
                
                ArrayList arrayOb = result.Properties;

                ArrayList totalResult = new ArrayList();
                

                foreach (object o2 in arrayOb)
                {
                    Dictionary<string, object> listOfPropsObj = o2 as Dictionary<string, object>;

                    if (listOfPropsObj.Keys.Count == 3) 
                    {
                        totalResult.Add(listOfPropsObj);
                    }
                }


                listResults.DataSource = totalResult;
                listResults.DataBind();
            }
        }
    }
}